<template>
	<view>
		<view class="box">
			<view class="title">订单信息</view>
			<view class="list">
				<view class="item">
					<text class="label">订单编号：</text>
					<text class="value u-line-1">{{detail.num}}</text>
				</view>
				<view class="item">
					<text class="label">下单时间：</text>
					<text class="value u-line-1">{{detail.createTime}}</text>
				</view>
			</view>
		</view>
		<view class="box">
			<view class="title">{{detail.title}}</view>
			<view class="list">
				<view class="item">
					<text class="label">供应商单位：</text>
					<text class="value u-line-1">{{detail.supplierName}}</text>
				</view>
				<view class="item">
					<text class="label">要求供应时间：</text>
					<text class="value u-line-1">{{detail.supplyTime}}</text>
				</view>
				<view class="item">
					<span class="label">卸货位置：</span>
					<span class="value u-line-1">{{detail.locationName}}</span>
				</view>
				<view class="item">
					<span class="label">预计所需算量：</span>
					<span class="value u-line-1">{{detail.totalBudget}}t</span>
				</view>
			</view>
		</view>
		
		<view class="box">
			<view class="title">审批流程</view>
			<view class="timeline">
				<u-time-line>
					<u-time-line-item v-for="(item,index) in detail.approvalProcessVos" :key="index" nodeTop="4">
						<template v-slot:node>
							<view class="u-node" :style="item.status != 1 || index == 0 ? 'background: #19be6b;' : ''">
								<u-icon :name="index == 0 ? 'yewuliufaqibeifen2x' : 'shenpi'" custom-prefix="custom-icon" color="#fff" :size="22"></u-icon>
							</view>
						</template>
						<template v-slot:content>
							<view>
								<view class="name">
									<text>{{item.opretorName}}</text>
									<u-tag v-if="item.status == 0" :text="item.opretorRoleName" type="warning" shape="circle" size="mini" mode="dark"/>
									<u-tag v-else :text="item.status == 1 ? '审批中' : item.status == 3 ? '审批通过' : '审批驳回'" :type="item.status == 1 ? 'info' : item.status == 3 ? 'success' : 'error'" shape="circle" size="mini" mode="dark"/>
								</view>
								<view class="desc" v-if="item.opretorDesc">{{item.opretorDesc}}</view>
								<view class="time">{{item.opretorTime}}</view>
							</view>
						</template>
					</u-time-line-item>
					
				</u-time-line>
			</view>
		</view>
		
		<view v-if="detail.status == -1" class="btn cancel">订单已取消</view>
		<view v-else class="btn" @click="cancel" v-if="userinfo.id == planDetail.createBy">取消订单</view>
	</view>
</template>

<script>
	export default{
		props:{
			orderId:{
				type: String,
				default: null
			},
			detail:{
				type:Object,
				default:()=>{}
			}
		},
		computed:{
			userinfo(){
				return JSON.parse(this.vuex_userInfo).user_info
			}
		},
		methods:{
			//拨打电话
			call(phone){
				uni.makePhoneCall({
				    phoneNumber: phone
				});
			},
			pageRefresh(){
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.$vm.refresh();
			},
			cancel(){
				uni.showModal({
					content:'确认取消该订单？',
					success: (res) => {
						if(res.confirm){
							this.$u.api.cancelOrder({id:this.orderId}).then(res => {
								if(res.code != 0){
									this.$u.toast(res.msg)
									return false
								}
								this.$u.toast('取消成功')
								uni.navigateBack({delta:1})
								this.pageRefresh()
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box{
		background: #FFFFFF;
		border-radius: 10rpx;
		padding: 24rpx;
		margin-bottom: 20rpx;
		.title{
			font-size: 34rpx;
			font-weight: 800;
			border-bottom: 1px solid rgba(0, 0, 0, 0.1);
			padding-bottom: 24rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.list{
			.item{
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 20rpx;
				font-size: 28rpx;
				.label{
					color: #798188;
				}
				.value{
					color:#333;
					max-width: 400rpx;
				}
			}
		}
		.info{
			display: flex;
			align-items: center;
			.icon{
				width: 64rpx;
				height: 64rpx;
				background: linear-gradient(180deg, #2AAFFF 0%, #1378FF 100%);
				border-radius: 50%;
				text-align: center;
				line-height: 64rpx;
				margin-right: 30rpx;
			}
			.info-bd{
				flex: 1;
				display: flex;
				flex-direction: column;
				.name-box{
					margin-bottom: 10rpx;
					.name{
						font-size: 28rpx;
						color: #1F1F22;
						font-weight: 600;
						margin-right: 15rpx;
					}
					.tel{
						font-size: 26rpx;
						color: #137AFF;
					}
				}
				.address{
					font-size: 28rpx;
					color: #1F1F22;
				}
			}
		}
	}
	.btn{
		margin-top: 40rpx;
		height: 88rpx;
		background: #B6D5FF;
		border-radius: 16rpx;
		text-align: center;
		line-height: 88rpx;
		font-size: 34rpx;
		color: #fff;
		&.cancel{
			background: #909399;
		}
	}
	.timeline{
		padding: 30rpx 20rpx 0;
		.name{
			display: flex;
			align-items: center;
			margin-bottom: 10rpx;
			text{
				margin-right: 20rpx;
				font-size: 28rpx;
			}
		}
		.time{
			font-size: 24rpx;
			color: #798188;
		}
		.u-node {
			width: 34rpx;
			height: 34rpx;
			border-radius: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			background: #d0d0d0;
		}
		.desc{
			color: rgba(150,150,150,1);
			margin-bottom: 6rpx;
		}
	}
</style>
